package edu.hawaii.its381b.client;

import com.google.gwt.safehtml.shared.SafeUri;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.HorizontalPanel;

public class Banner extends Composite{
	private Image bannerImage;
	private String initialsEntered,
				   bannedWords[]={"FUK","FCK","ASS","FU","FKU","WTF","SHT","FML"};
	private TextBox initialsTextBox = new TextBox();

	VerticalPanel mainPanel;
	public Banner() {
		super();
		mainPanel = new VerticalPanel();
		mainPanel.setStyleName("mainRootStyle");
		mainPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
		
		initWidget(mainPanel);
		mainPanel.setSize("600px", "200px");
		SafeUri bannerURI = HermitCrabResources.INSTANCE.banner().getSafeUri();
		bannerImage= new Image(bannerURI);
		
		mainPanel.add(bannerImage);
		mainPanel.setCellVerticalAlignment(bannerImage, HasVerticalAlignment.ALIGN_MIDDLE);
		mainPanel.setCellHorizontalAlignment(bannerImage, HasHorizontalAlignment.ALIGN_CENTER);
		bannerImage.setSize("590px", "190px");
		
		HorizontalPanel initialsPanel = new HorizontalPanel();
		mainPanel.add(initialsPanel);
		initialsPanel.setWidth("220px");
		
		Label enterInitialsLabel = new Label("Enter your initials here:");
		initialsPanel.add(enterInitialsLabel);
		initialsPanel.setCellVerticalAlignment(enterInitialsLabel, HasVerticalAlignment.ALIGN_MIDDLE);
	/*	initialsTextBox.addFocusHandler(new FocusHandler() {
			public void onFocus(FocusEvent event) {
//				RootPanel.get().add(new Label("We have Focus!"));
				inTextBox = true;
				event.
			}
		});*/
		
		initialsPanel.add(initialsTextBox);
		initialsTextBox.setWidth("60px");
		initialsTextBox.setVisibleLength(3);
		initialsTextBox.setName("NameThingy");
		initialsTextBox.setMaxLength(3);
						
		initialsTextBox.setFocus(true);
		initialsTextBox.selectAll();
		
	}
	public void setFocus(){
		initialsTextBox.setFocus(true);
	}
	
	
	public String getInitials(){
		initialsEntered = initialsTextBox.getText().toUpperCase();

		if(initialShouldBeFiltered()){
			initialsEntered = "LOL";
		}
		if(initialsEntered.isEmpty()){
			initialsEntered = "WAQ";
		}
		return initialsEntered;
	}

	private Boolean initialShouldBeFiltered(){
		Boolean checkedInitials = false;
		for(int currentWord = 0; currentWord < bannedWords.length; currentWord++){

			if(initialsEntered.equals(bannedWords[currentWord])){
				checkedInitials  = true;
			}
		}
	return checkedInitials ;
	}
}